package com.common.http.basecore.utils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by hai8108 on 16/7/24.
 */
public class LoggingInterceptor implements Interceptor{
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        long t1 = System.nanoTime();
        request = request.newBuilder().addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
                .build();
        LogInfo.log("LoggingInterceptor",(String.format("Sending request %s on %s%n%s",
                request.url(), chain.connection(), request.headers())));
        Response response = chain.proceed(request);
//        long t2 = System.nanoTime();
//        LogInfo.log("LoggingInterceptor",(String.format("Received response for %s in %.1fms%n%s",
//                response.request().url(), (t2 - t1) / 1e6d, response.headers())));
        return response;
    }
}
